package com.yc.cinema.mapper;

import com.yc.cinema.entity.Plan;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import javax.annotation.Resource;
import java.util.List;

public interface PlanMapper {

//    Plan selectById(int id);


    //  @Resource ==>  <resultMap>
//  @Result ==>  <Result>
//  id = true ==> <id>  指定主键字段
    @Results(
            id = "rm2",
            value = {
                    @Result(id = true, column = "id", property = "id"),
                    @Result(column = "play_time", property = "playTime"),
                    @Result(column = "mid", property = "mid"),
                    @Result(column = "mid", property = "movie",
                            one = @One(
                                    select = "com.yc.cinema.mapper.MovieMapper.selectById",
                                    fetchType = FetchType.LAZY)
                    )
            }
    )
    @Select("select * from plan where id = #{id}")
    Plan selectById(int id);

    //根据影片查询拍片记录
    List<Plan> selectByMid(int mid);
}
